package com.tenton.servlet;

import com.tenton.pojo.Province;
import com.tenton.service.Impl.ProvinceServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Date: 2021/1/14
 * @Author: Tenton
 * @Description:
 */
@WebServlet(name = "ProvinceServlet" ,urlPatterns = "/provinceServlet")
public class ProvinceServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码格式，防止乱码
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        ProvinceServiceImpl provinceServiceImpl = new ProvinceServiceImpl();
        List<Province> provinces = provinceServiceImpl.listProvince();
        request.setAttribute("provinces",provinces);
        request.getRequestDispatcher("/regist.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
